#pragma once

// Windows
#define WIN32_LEAN_AND_MEAN
#include <windows.h>

// STL
#include <string>
#include <sstream>
#include <vector>

// 3DS Max
#include <max.h>
#include <IGame/IGame.h>

// class ID for exporter
#define ARELLOEXPORTER_CLASS_ID Class_ID(0x45dc4fb5, 0x73ab0ef9)

// helpers for extraction path and file name
inline std::string GetPathFromFileName(const std::string & fileName)
{
	size_t slash1 = fileName.rfind("\\");
	size_t slash2 = fileName.rfind("/");
	size_t slash  = 0;

	if(slash1 == fileName.npos && slash2 == fileName.npos)
	{
		return "";
	}
	else if(slash1 != fileName.npos && slash2 != fileName.npos)
	{
		slash = max(slash1, slash2) + 1;
	}
	else
	{
		slash = (slash1 == fileName.npos ? slash2 : slash1) + 1;
	}

	return fileName.substr(0, slash);
}

inline std::string GetFileNameFromPath(const std::string & fileName)
{
	size_t slash1 = fileName.rfind("\\");
	size_t slash2 = fileName.rfind("/");
	size_t slash  = 0;

	if(slash1 != fileName.npos && slash2 != fileName.npos)
	{
		slash = max(slash1, slash2) + 1;
	}
	else if(slash1 != fileName.npos || slash2 != fileName.npos)
	{
		slash = (slash1 == fileName.npos ? slash2 : slash1) + 1;
	}

	size_t dot = fileName.rfind(".");

	return fileName.substr(slash, dot == fileName.npos ? fileName.npos : dot - slash);
}

inline std::string GetFileExtensionFromPath(const std::string & fileName)
{
	size_t dot = fileName.rfind(".");
	if(dot == fileName.npos)
		return "";

	return fileName.substr(dot);
}

inline std::string StringToLower(const std::string & original)
{
	std::string result = original;

	for(int i = 0; i < result.length(); i++)
		result[i] = tolower(result[i]);

	return result;
}